<?
require_once('../../pers/inc.config.php');
if (file_exists(RGL_FS_WEB_ROOT.'/stop.txt')) {
	header("location: ".RGL_URL_ROOT."/app/_com/stop.php");
	exit();
}
if (!file_exists(RGL_FS_WEB_ROOT."/pers/licenza.rgl")) {
	die("manca licenza !!!"); 
}
require_once(RGL_FS_WEB_ROOT.'/app/_inc/inc.set1.php');
require_once(RGL_FS_WEB_ROOT.'/app/_inc/class.rglSession.php');
require_once(RGL_FS_WEB_ROOT.'/app/_inc/funct.html.php');

// configura il gestore dell'errore definito dall'utente
$oldErrorHandler = set_error_handler("erroHandler");

session_start();

$msg = reqVar('msgpag');

if (reqVar('azione')=='login'){
	$msg .= creaSubSess();
}
?>
<html>
<HEAD>
<META Name="expires" CONTENT= "Mon, 1 Jan 2000 00:00:00 GMT">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<META HTTP-EQUIV="content-language" content="it">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="shortcut icon" href='<?=RGL_URL_ROOT?>/app/_img/rgl.ico' type="image/x-icon" />
<link rel="stylesheet" href="<?=RGL_URL_ROOT?>/app/_com/css.stilePar.php" type="text/css">
<title>REGULUS - Log-in</title>
<script type="text/javascript">
</script>
</HEAD>
<body style="font-family:arial;margin:10;background-color:#dddddd;" onLoad=''>
<br/><br/><br/><br/><br/>
<form name="menu" action="<?=$_SERVER['PHP_SELF']?>" method="POST">
<input type='hidden' name='azione' value="login">
<table class="tab1" cellspacing="1" cellpadding="3" align='center'
	style='font-family:arial;background-color:#ffffff;width:100px;border:#ffffff 10px solid;'>
	<tr>
	   <td width='1%' ><?php echo getHtmlImgLogo();?></td>
      <td width='99%'><?=getHtmlImgGen("Rating aziende", 300, 24, 'FFFFFF', '000000', 18)?>
         <br/><?=getHtmlImgGen("Log-in", 300, 22, 'FFFFFF', '000000', 14)?>

      </td>
	</tr>
	<tr>
		<td colspan='2' style='border-top:black 1px solid;text-align:right;'>&nbsp;</td>
	</tr>
   <tr>
      <td class="cmd1" align='right'><?=_t('Utente')?>: &nbsp;</td>
      <td class="cmd1">
      	<? echo getHtmlTextCode('login',20);?>
      </td>
   </tr>
   <tr>
      <td class="cmd1" align='right'>Password: &nbsp;</td>
      <td class="cmd1">
      	<? echo getHtmlPassword('pwd',20);?>
      	&nbsp;&nbsp;&nbsp;
      	<input type='submit' name='invia' value="<?=_t('entra')?>" 
      		style='border:none;color:black;background-color:white;font-weight:bold;text-decoration:underline;'/>
      </td>
   </tr>
	<tr>
		<td colspan='2'>&nbsp;</td>
	</tr>
	<tr>
		<td colspan='2' style='border-top:black 1px solid;text-align:right;'>
			<?readfile(RGL_FS_WEB_ROOT."/app/_inc/versione.txt")?></td>
	</tr>
   <tr>
      <td class="err1" align='center' colspan='2'><?php echo $msg;?>&nbsp;</td>
   </tr>
</table>
</form>
</body>
</html>
<?
exit();

function creaSubSess() {
	global $objDB, $objSess;

	$objSess = new rglSession();
	if (!$objSess->login(reqVar('login'),reqVar('pwd'))) {
		return $objSess->error;
	}
   $k=1;
   while(isset($_SESSION[RGL_SESS_OBJ_PREF.$k]) and $k < 100) {$k++;}
   define('SESSOBJ',RGL_SESS_OBJ_PREF.$k);
   define('XSN',"$k.1");
	$_SESSION[SESSOBJ] = $objSess;
	
	header("Location: ".$objSess->getUrlIniz());
	exit();
}

function erroHandler($errno, $errstr, $errfile, $errline){
   switch ($errno) {
   case E_USER_WARNING:
   case E_USER_NOTICE:
   case E_WARNING:
   case E_NOTICE:
	case E_DEPRECATED:
		file_put_contents(RGL_FS_TEMP_DIR."/loginwarning.txt" , "$errstr in $errfile alla linea $errline <br>");
     	return;
   default:
      $uself = urlencode($_SERVER['PHP_SELF']);
      $uerrstr = urlencode($errstr);
      $uerrfile = urlencode($errfile);
      // aggiungere in querystring $errno $errstr $errfile $errline
      echo '<script>window.top.location.href = "'.RGL_URL_ROOT.'/app/_com/error.php?'.
         'pagina_self='.$uself.'&errno='.$errno.'&errstr='.$uerrstr.
         '&errfile='.$uerrfile.'&errline='.$errline.'"</script>';
      exit;
      break;
   }
}
